package utils

import (
	"math/rand"
	"time"
)

// 各类生成函数

const (
	intChars  = "0123456789"
	messChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
)

// RandomIntChars 生成 n 位随机整数字符串
// n 的值非法时记为4
func RandomIntChars(n int) string {
	if n < 1 {
		n = 4
	}
	chars := make([]byte, 0, n)
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	for i := 0; i < n; i++ {
		chars = append(chars, intChars[r.Intn(len(intChars))])
	}
	return string(chars)
}

// RandomChars 生成 n 位随机字符串
// n 的值非法时记为4
func RandomChars(n int) string {
	if n < 1 {
		n = 4
	}
	chars := make([]byte, 0, n)
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	for i := 0; i < n; i++ {
		chars = append(chars, messChars[r.Intn(len(messChars))])
	}
	return string(chars)
}
